
//init state


const state = () => ({
  param: [
    /*{
      orderComMsgId: 2,//订单商品信息编号
      comId: 2,//商品编号
      keepSetSerId: 2,//保修服务编号
      orderId: '210807179610847412',//订单编号
      ordernum: 2//订单数量
    },
    {
      orderComMsgId: 3,
      comId: 3,
      keepSetSerId: 3,
      orderId: '210807179610847413',
      ordernum: 2
    },
    {
      orderComMsgId: 4,
      comId: 4,
      keepSetSerId: undefined,
      orderId: '210807179610847412',
      ordernum: 4
    }*/
  ]
})

//getters
const getters = {
/*  getOrderMsgAndOrderData(state, getters, rootState, rootGetters){//获取订单信息表信息和订单表信息
    return state.param.map(item => {
      let orderMsg = rootGetters["Order/getDataByOrderId"](item.orderId);
      item = {...item,...orderMsg};//通过浅拷贝将ordermsg的信息存放到对象当中
      let comMsg = rootGetters["DetailData/getComImgAndComPrice"](item.comId);
      item = {...item,...comMsg};//通过浅拷贝将商品的部分数据存放到对象当中
      if (item.keepSetSerId){//确保保修编号有才查询
        let serviceMsg = rootGetters["ServiceMsg/getSerNameBySerId"](item.keepSetSerId);
        item.serviceMsg = serviceMsg;
      }
      return item;
    });
  },*/
  getManyComDataByOrderId(state, getters, rootState, rootGetters){//通过订单编号查询商品信息
    return function (orderId) {
      let comMsgArr = state.param.filter(item => {
        return item.orderId == orderId;
      });
      return comMsgArr.map(item => {
        let comMsg = rootGetters["DetailData/getComImgAndComPrice"](item.comId);
        item = {...item,...comMsg};
        let serviceMsg = rootGetters["ServiceMsg/getSerNameBySerId"](item.keepSetSerId);
        item = {...item,...{serviceMsg: serviceMsg}};
        return item;
      });
    }
  },
  refreshOrderComMsgSessionStorageData(state){//更新session中的数据
    sessionStorage.setItem("OrderComMsg",JSON.stringify(state.param))
  }
}

//actions
const actions = {
  loadDataForOrderComMsg({commit},payload){//加载数据
    commit("loadDataForOrderComMsgMut",payload);
  }
}

//mutations
const mutations = {
  loadDataForOrderComMsgMut(state,val){//加载数据
    state.param = [...val];
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
